package com.ruoyi.paper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paper.domain.ExamOption;
import com.ruoyi.paper.service.IExamOptionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试题选项Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/jxsx/option")
public class ExamOptionController extends BaseController
{
    private String prefix = "jxsx/option";

    @Autowired
    private IExamOptionService examOptionService;

    @RequiresPermissions("jxsx:option:view")
    @GetMapping()
    public String option()
    {
        return prefix + "/option";
    }

    /**
     * 查询试题选项列表
     */
    @RequiresPermissions("jxsx:option:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamOption examOption)
    {
        startPage();
        List<ExamOption> list = examOptionService.selectExamOptionList(examOption);
        return getDataTable(list);
    }

    /**
     * 导出试题选项列表
     */
    @RequiresPermissions("jxsx:option:export")
    @Log(title = "试题选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamOption examOption)
    {
        List<ExamOption> list = examOptionService.selectExamOptionList(examOption);
        ExcelUtil<ExamOption> util = new ExcelUtil<ExamOption>(ExamOption.class);
        return util.exportExcel(list, "试题选项数据");
    }

    /**
     * 新增试题选项
     */
    @RequiresPermissions("jxsx:option:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试题选项
     */
    @RequiresPermissions("jxsx:option:add")
    @Log(title = "试题选项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamOption examOption)
    {
        return toAjax(examOptionService.insertExamOption(examOption));
    }

    /**
     * 修改试题选项
     */
    @RequiresPermissions("jxsx:option:edit")
    @GetMapping("/edit/{optionId}")
    public String edit(@PathVariable("optionId") String optionId, ModelMap mmap)
    {
        ExamOption examOption = examOptionService.selectExamOptionByOptionId(optionId);
        mmap.put("examOption", examOption);
        return prefix + "/edit";
    }

    /**
     * 修改保存试题选项
     */
    @RequiresPermissions("jxsx:option:edit")
    @Log(title = "试题选项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamOption examOption)
    {
        return toAjax(examOptionService.updateExamOption(examOption));
    }

    /**
     * 删除试题选项
     */
    @RequiresPermissions("jxsx:option:remove")
    @Log(title = "试题选项", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examOptionService.deleteExamOptionByOptionIds(ids));
    }
}
